﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.Entities_DAL
{
    public class DOITUONG_DAL:BaseDAL
    {
        public DataTable Select()
        {
            var sql = @"SELECT * FROM DOI_TUONG";
            return ExecuteQuery(sql);
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM DOI_TUONG WHERE MSSV = '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (DOI_TUONG)obj;
            string sql = @"set dateformat dmy;INSERT INTO DOI_TUONG(MSSV, LOP_HOC, C_VU) VALUES('{0}',N'{1}',N'{2}')";
            sql = string.Format(sql, o.MSSV, o.LOP_HOC, o.C_VU);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (DOI_TUONG)obj;
            string sql = @"set dateformat dmy;UPDATE DOI_TUONG SET LOP_HOC=N'{1}', C_VU = N'{2}' where MSSV='{0}'";
            sql = string.Format(sql, o.MSSV, o.LOP_HOC, o.C_VU);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public string Select_count()
        {
            string sql = @"SELECT count(MSSV) as id FROM DOI_TUONG";
            var tb = ExecuteQuery(sql);
            return tb.Rows.Count > 0 ? tb.Rows[0]["id"] + "" : "0";
        }
    }
}
